/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 *
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0 2010-12-29 上午11:01:15
 *
 * User.java 
 *
 *
 *******************************************************************/
package com.transer.persistance.bean;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.transer.utils.Types;
import com.transer.utils.Utils;

/**
 * 
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class User implements Serializable {
	private static final long serialVersionUID = 3422282295660670068L;
	/** ID */
	private int id;
	/** 昵称 */
	private String nikeName;
	/** 用户类型 */
	private int type;
	/** 密码 */
	private String password;
	/** 电子邮件 */
	private String email;
	/** 真实姓名 */
	private String realName;
	/** 手机号码 */
	private String cellPhone;

	/** 公司名称 */
	private String companyName;
	/** 公司注册号 */
	private String companyNumber;
	/** 联系电话 */
	private String contactPhone;

	/** 关于我们 */
	private String aboutme = "这家伙很懒,什么也没留下.";

	/** 省份 */
	private int provice;
	/** 城市 */
	private int city;

	/** 即时通信 */
	private String im;

	/** 毕业学院 */
	private String college;
	/** 经验 */
	private int experience;
	/** 证书 */
	private String certificate;
	/** 银行代码 */
	private int bank;
	/** 银行账号 */
	private String bankNumber;
	/** 擅长领域 */
	private String goodAtArea;
	/** 擅长类型 */
	private String goodAt = "50001";
	/** 母语 */
	private String nativeLang = "20001";

	/** 支付宝 */
	private String alipay;

	/** 是否激活 */
	protected boolean active = true;
	/** 激活码 */
	protected String activeCode;

	/** 平均评分 */
	protected int averagePoint = 0;
	/** 总消费或者赚取费用 */
	protected int totalMoney = 0;
	/** 当前剩余费用 */
	protected int leftMoney = 0;

	// 关键字
	protected String keyWords;
	// 注册日期
	protected Date regDate;
	/** 最近登陆日期 */
	protected Date lastLoginTime;

	/** 配对语言 */
	protected List<ProfileLanguage> languagePairs;

	/**
	 * @return the keyWords
	 */
	public String getKeyWords() {
		return keyWords;
	}

	/**
	 * @param keyWords
	 *            the keyWords to set
	 */
	public void setKeyWords(String keyWords) {
		this.keyWords = keyWords;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getIm() {
		return im;
	}

	public void setIm(String im) {
		this.im = im;
	}

	public String getCellPhone() {
		return cellPhone;
	}

	public void setCellPhone(String cellPhone) {
		this.cellPhone = cellPhone;
	}

	public String getAlipay() {
		return alipay;
	}

	public void setAlipay(String alipay) {
		this.alipay = alipay;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public int getProvice() {
		return provice;
	}

	public void setProvice(int provice) {
		this.provice = provice;
	}

	public int getCity() {
		return city;
	}

	public void setCity(int city) {
		this.city = city;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	/**
	 * @return the activeCode
	 */
	public String getActiveCode() {
		return activeCode;
	}

	/**
	 * @param activeCode
	 *            the activeCode to set
	 */
	public void setActiveCode(String activeCode) {
		this.activeCode = activeCode;
	}

	public int getAveragePoint() {
		return averagePoint;
	}

	public void setAveragePoint(int averagePoint) {
		this.averagePoint = averagePoint;
	}

	public int getTotalMoney() {
		return totalMoney;
	}

	public void setTotalMoney(int totalMoney) {
		this.totalMoney = totalMoney;
	}

	/**
	 * @return the leftMoney
	 */
	public int getLeftMoney() {
		return leftMoney;
	}

	/**
	 * @param leftMoney
	 *            the leftMoney to set
	 */
	public void setLeftMoney(int leftMoney) {
		this.leftMoney = leftMoney;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the nikeName
	 */
	public String getNikeName() {
		return nikeName;
	}

	/**
	 * @param nikeName
	 *            the nikeName to set
	 */
	public void setNikeName(String nikeName) {
		this.nikeName = nikeName;
	}

	/**
	 * @return the regDate
	 */
	public Date getRegDate() {
		return regDate;
	}

	/**
	 * @param regDate
	 *            the regDate to set
	 */
	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	/**
	 * @return the lastLoginTime
	 */
	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	/**
	 * @param lastLoginTime
	 *            the lastLoginTime to set
	 */
	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	/**
	 * @return the companyName
	 */
	public String getCompanyName() {
		return companyName;
	}

	/**
	 * @param companyName
	 *            the companyName to set
	 */
	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	/**
	 * @return the companyNumber
	 */
	public String getCompanyNumber() {
		return companyNumber;
	}

	/**
	 * @param companyNumber
	 *            the companyNumber to set
	 */
	public void setCompanyNumber(String companyNumber) {
		this.companyNumber = companyNumber;
	}

	/**
	 * @return the contactPhone
	 */
	public String getContactPhone() {
		return contactPhone;
	}

	/**
	 * @param contactPhone
	 *            the contactPhone to set
	 */
	public void setContactPhone(String contactPhone) {
		this.contactPhone = contactPhone;
	}

	/**
	 * @return the aboutme
	 */
	public String getAboutme() {
		return aboutme;
	}

	/**
	 * @param aboutme
	 *            the aboutme to set
	 */
	public void setAboutme(String aboutme) {
		this.aboutme = aboutme;
	}

	/**
	 * @return the college
	 */
	public String getCollege() {
		return college;
	}

	/**
	 * @param college
	 *            the college to set
	 */
	public void setCollege(String college) {
		this.college = college;
	}

	/**
	 * @return the experience
	 */
	public int getExperience() {
		return experience;
	}

	/**
	 * @param experience
	 *            the experience to set
	 */
	public void setExperience(int experience) {
		this.experience = experience;
	}

	/**
	 * @return the certificate
	 */
	public String getCertificate() {
		return certificate;
	}

	/**
	 * @param certificate
	 *            the certificate to set
	 */
	public void setCertificate(String certificate) {
		this.certificate = certificate;
	}

	/**
	 * @return the bank
	 */
	public int getBank() {
		return bank;
	}

	/**
	 * @param bank
	 *            the bank to set
	 */
	public void setBank(int bank) {
		this.bank = bank;
	}

	/**
	 * @return the bankNumber
	 */
	public String getBankNumber() {
		return bankNumber;
	}

	/**
	 * @param bankNumber
	 *            the bankNumber to set
	 */
	public void setBankNumber(String bankNumber) {
		this.bankNumber = bankNumber;
	}

	/**
	 * @return the goodAtArea
	 */
	public String getGoodAtArea() {
		return goodAtArea;
	}

	/**
	 * @param goodAtArea
	 *            the goodAtArea to set
	 */
	public void setGoodAtArea(String goodAtArea) {
		this.goodAtArea = goodAtArea;
	}

	/**
	 * @return the languagePairs
	 */
	public List<ProfileLanguage> getLanguagePairs() {
		return languagePairs;
	}

	/**
	 * @param languagePairs
	 *            the languagePairs to set
	 */
	public void setLanguagePairs(List<ProfileLanguage> languagePairs) {
		this.languagePairs = languagePairs;
	}

	/**
	 * @return the goodAt
	 */
	public String getGoodAt() {
		return goodAt;
	}

	/**
	 * @param goodAt
	 *            the goodAt to set
	 */
	public void setGoodAt(String goodAt) {
		this.goodAt = goodAt;
	}

	/**
	 * @return the nativeLang
	 */
	public String getNativeLang() {
		return nativeLang;
	}

	/**
	 * @param nativeLang
	 *            the nativeLang to set
	 */
	public void setNativeLang(String nativeLang) {
		this.nativeLang = nativeLang;
	}

	public boolean isDetailComplete() {
		Field[] fields = this.getClass().getDeclaredFields();

		try {
			for (Field field : fields) {
				if (Modifier.isPrivate(field.getModifiers())) {
					field.setAccessible(true);
					if (Types.isInteger(field.getType())) {
						if (field.getInt(this) <= 0) {
							return false;
						}
					} else if (Types.isString(field.getType())) {
						if (StringUtils.isEmpty(Utils.getString(field.get(this)))) {
							return false;
						}
					}
					field.setAccessible(false);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		/** 公司名称 */
		// String companyName;
		/** 公司注册号 */
		// String companyNumber;
		/** 联系电话 */
		// String contactPhone;
		return true;
	}

	/**
	 * 没有设置语言
	 * 
	 * @return
	 */
	public boolean langNotSetup() {
		return languagePairs == null || languagePairs.size() == 0 || StringUtils.isEmpty(goodAtArea) || StringUtils.isEmpty(goodAt) || StringUtils.isEmpty(nativeLang);
	}

	public boolean companyNotSetup() {
		return StringUtils.isEmpty(companyName) || StringUtils.isEmpty(companyNumber) || StringUtils.isEmpty(contactPhone) || StringUtils.isEmpty(aboutme);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		Field[] fields = this.getClass().getDeclaredFields();
		StringBuffer sb = new StringBuffer();
		try {
			for (Field field : fields) {
				field.setAccessible(true);
				sb.append(field.getName() + ":" + field.get(this) + "|");
				field.setAccessible(false);
			}
		} catch (Exception e) {
		}
		return sb.toString();
	}
}